<?php

namespace Queue\Task;

use Queue\Interfaces\TaskInterface;

final class Sha1ChecksumTask implements TaskInterface
{
    private string $filepath;

    private string $checksum;

    public function __construct(string $filepath, string $checksum)
    {
        $this->filepath = $filepath;
        $this->checksum = $checksum;
    }

    public function execute(): void
    {
        $fileChecksum = \sha1_file($this->filename);

        echo \sprintf("sha1checksum is %s", $fileChecksum && $fileChecksum == $checksum ? 'valid' : 'invalid');
    }

    public function serialize(): string
    {
        return \serialize([
            $this->filename,
            $this->checksum,
        ]);
    }

    public function unserialize(string $serialized): mixed
    {
        [$filename, $checksum] = [\unserialize($serialized)];

        $this->filename = $filename;
        $this->checksum = $checksum;
    }
}
